﻿
using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV
{
    public partial class xinzeng_gequ : Form
    {
        DBHelper db = new DBHelper();
        DataSet set = new DataSet();
        string name;
        public xinzeng_gequ()
        {
            InitializeComponent();
        }


        private void xinzeng_gequ_Load(object sender, EventArgs e)
        {
            db.OpenConnection();
            string sql = "select * from singer_type";
            SqlCommand command = new SqlCommand(sql, db.Connection);
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                this.comboBox1.Items.Add(reader["singertype_name"]);
            }
            reader.Close();



            db.OpenConnection();
            string sql1 = "select * from singer_info";
            SqlDataAdapter command1 = new SqlDataAdapter(sql1, db.Connection);
            command1.Fill(set, "singer_info");
            //和下拉列表关联数据
            this.comboBox2.DataSource = set.Tables["singer_info"];
            //绑定实际值
            this.comboBox2.ValueMember = "singer_id";
            //绑定显示的值
            this.comboBox2.DisplayMember = "singer_name";
            db.CloseConnection();

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        //添加
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Trim().Equals(string.Empty)||
                this.textBox1.Text.Trim().Equals(string.Empty)||
                this.textBox3.Text.Trim().Equals(string.Empty)||
                this.textBox5.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("请填写信息");
            }
            else
            {
                db.OpenConnection();
                string sql = "";
                sql = "select * from song_info where song_name=N'"+this.textBox1.Text+"'";
                SqlCommand comm = new SqlCommand(sql,db.Connection);
                int i = Convert.ToInt32(comm.ExecuteScalar());
                if (i>0)
                {
                    MessageBox.Show("歌名重复，请重新输入");
                    return;
                }
                else
                {
                    int one = 0;
                    if (this.comboBox1.Text == "大陆")
                    {
                        one = 1;
                    }
                    else if (this.comboBox1.Text == "香港")
                    {
                        one = 2;
                    }
                    else if (this.comboBox1.Text == "台湾")
                    {
                        one = 3;
                    }
                    else if (this.comboBox1.Text == "欧美")
                    {
                        one = 4;
                    }
                    else if (this.comboBox1.Text == "日韩")
                    {
                        one = 5;
                    }
                     

                    sql = "insert into song_info(song_name,song_ab,song_word_count,song_play_count,songtype_id,singer_id,song_url)values(N'" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox5.Text + "','" + one + "','" + this.comboBox2.SelectedValue.ToString() + "','"+this.textBox4.Text+"')";
                    SqlCommand comm1 = new SqlCommand(sql, db.Connection);
                    int count = comm1.ExecuteNonQuery();

                    MessageBox.Show("添加成功");


                    db.CloseConnection();
                }
                
            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            DialogResult result = fileDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                name = fileDialog.FileName.Substring(fileDialog.FileName.LastIndexOf("\\") + 1);
                Console.WriteLine(name);
                this.textBox4.Text = name;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
            int i;
            i = this.textBox1.Text.Length;
            this.textBox3.Text = i.ToString();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
